Skip to content

Conversation

@Bashmunta
Copy link
Contributor

AncientSize for the in-memory freezer could over-report because memoryTable.size was not decremented on head or tail truncations. This change subtracts the sizes of removed items in truncateHead and truncateTail, and re-allocates the slice on tail truncation to avoid retaining the backing array. The result brings the in-memory freezer’s size accounting in line with the on-disk freezer’s semantics and the documented meaning of size.

return errors.New("truncation below tail")
}
t.data = t.data[:items-t.offset]
removeFrom := items - t.offset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something like this?

	for i := int(items - t.offset); i < len(t.data); i++ {
		if t.size > uint64(len(t.data[i])) {
			t.size -= uint64(len(t.data[i]))
		} else {
			t.size = 0
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something like this?

	for i := int(items - t.offset); i < len(t.data); i++ {
		if t.size > uint64(len(t.data[i])) {
			t.size -= uint64(len(t.data[i]))
		} else {
			t.size = 0
		}
	}

good idea, refactored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants